
R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> ## pairwise comparisons coder race correlates with photos observed
> ## only target photos used for analysis
> ##
> ## August 9, 2019
> ##
> ## Kevin Quinn
> ## University of Michigan
> ##
> 
> library(MCMCpack)
Loading required package: coda
Loading required package: MASS
##
## Markov Chain Monte Carlo Package (MCMCpack)
## Copyright (C) 2003-2019 Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park
##
## Support provided by the U.S. National Science Foundation
## (Grants SES-0350646 and SES-0350613)
##
> set.seed(416258)
> 
> mydata <- read.csv("../ScaleRaceSpring2017clean.csv")
> 
> 
> ## subset data
> mydata <- mydata[(mydata$condition %in% c("P2B", "P2W") & mydata$R.race == "Black") | (mydata$condition %in% c("P1B", "P1W") & mydata$R.race == "White"),]
> 
> 
> ## keep responses and photo IDs but nothing else
> target.inds <- c(6, 7, 10, 12, 15, 17, 19, 20, 22, 23)
> keep.vars <- c(paste("X", target.inds, "_Q58", sep=""),
+                paste("X", target.inds, "a.id", sep=""),
+                paste("X", target.inds, "b.id", sep=""))
> 
> mydata.sub <- mydata[, keep.vars]
> 
> 
> 
> ## reshape into long format
> mydata.sub.long <- reshape(mydata.sub, direction="long",
+                            varying=list(c(1:10), c(11:20), c(21:30)),
+                            v.names=c("Y", "photoID.a", "photoID.b"),
+                            ids=rownames(mydata.sub))
> 
> ## keep only obs with non-missing values for MM
> mydata.sub.long <- na.omit(mydata.sub.long)
> mydata.sub.long <- mydata.sub.long[mydata.sub.long$Y != "",]
> 
> 
> ## convert to character variables
> mydata.sub.long$Y <- as.character(mydata.sub.long$Y)
> mydata.sub.long$photoID.a <- as.character(mydata.sub.long$photoID.a)
> mydata.sub.long$photoID.b <- as.character(mydata.sub.long$photoID.b)
> 
> ## recode Y to match what MCMCpaircompare expects
> for (i in 1:nrow(mydata.sub.long)){
+     if (mydata.sub.long$Y[i] == "the person in photo 1"){
+         mydata.sub.long$Y[i] <- mydata.sub.long$photoID.a[i]
+     }
+     if (mydata.sub.long$Y[i] == "the person in photo 2"){
+         mydata.sub.long$Y[i] <- mydata.sub.long$photoID.b[i]
+     }    
+ }
> 
> mydata.sub.long <- mydata.sub.long[, c(5, 3, 4, 2)]
> 
> mydata.sub.long <- mydata.sub.long[sample(1:nrow(mydata.sub.long),
+                                           size=1000, replace=FALSE),]
> 
> cat("\n\nN =", nrow(mydata.sub.long), "\n\n") 


N = 1000 

> 
> 
> ## starting values and set up
> pnames <- sort(unique(c(mydata.sub.long$photoID.a, mydata.sub.long$photoID.b)))
> 
> raw.counts <- table(mydata.sub.long$Y)
> zero.names <- pnames[!(pnames %in% names(raw.counts))]
> if (length(zero.names > 0)){
+   old.names <- names(raw.counts)
+   raw.counts <- c(rep(0, length(zero.names)), raw.counts)
+   names(raw.counts) <- c(zero.names, old.names)
+ }
> raw.counts <- raw.counts[pnames]
> raw.ranks <- rank(raw.counts)
> theta.start <- 2*(raw.ranks / length(pnames) - 0.5)
> 
> 
> 
> b1.pairwise.out <- MCMCpaircompare(mydata.sub.long,
+                                    theta.constraints=list(mw045.J1="-",
+                                                           mb017.J2="+"),
+                                    theta.start=theta.start,
+                                    alpha.fixed=TRUE,
+                                    burnin=50000, mcmc=1000000, thin=50,
+                                    verbose=10000, seed=516495
+                          )


MCMCpaircompare iteration 1 of 1050000 


MCMCpaircompare iteration 10001 of 1050000 


MCMCpaircompare iteration 20001 of 1050000 


MCMCpaircompare iteration 30001 of 1050000 


MCMCpaircompare iteration 40001 of 1050000 


MCMCpaircompare iteration 50001 of 1050000 


MCMCpaircompare iteration 60001 of 1050000 


MCMCpaircompare iteration 70001 of 1050000 


MCMCpaircompare iteration 80001 of 1050000 


MCMCpaircompare iteration 90001 of 1050000 


MCMCpaircompare iteration 100001 of 1050000 


MCMCpaircompare iteration 110001 of 1050000 


MCMCpaircompare iteration 120001 of 1050000 


MCMCpaircompare iteration 130001 of 1050000 


MCMCpaircompare iteration 140001 of 1050000 


MCMCpaircompare iteration 150001 of 1050000 


MCMCpaircompare iteration 160001 of 1050000 


MCMCpaircompare iteration 170001 of 1050000 


MCMCpaircompare iteration 180001 of 1050000 


MCMCpaircompare iteration 190001 of 1050000 


MCMCpaircompare iteration 200001 of 1050000 


MCMCpaircompare iteration 210001 of 1050000 


MCMCpaircompare iteration 220001 of 1050000 


MCMCpaircompare iteration 230001 of 1050000 


MCMCpaircompare iteration 240001 of 1050000 


MCMCpaircompare iteration 250001 of 1050000 


MCMCpaircompare iteration 260001 of 1050000 


MCMCpaircompare iteration 270001 of 1050000 


MCMCpaircompare iteration 280001 of 1050000 


MCMCpaircompare iteration 290001 of 1050000 


MCMCpaircompare iteration 300001 of 1050000 


MCMCpaircompare iteration 310001 of 1050000 


MCMCpaircompare iteration 320001 of 1050000 


MCMCpaircompare iteration 330001 of 1050000 


MCMCpaircompare iteration 340001 of 1050000 


MCMCpaircompare iteration 350001 of 1050000 


MCMCpaircompare iteration 360001 of 1050000 


MCMCpaircompare iteration 370001 of 1050000 


MCMCpaircompare iteration 380001 of 1050000 


MCMCpaircompare iteration 390001 of 1050000 


MCMCpaircompare iteration 400001 of 1050000 


MCMCpaircompare iteration 410001 of 1050000 


MCMCpaircompare iteration 420001 of 1050000 


MCMCpaircompare iteration 430001 of 1050000 


MCMCpaircompare iteration 440001 of 1050000 


MCMCpaircompare iteration 450001 of 1050000 


MCMCpaircompare iteration 460001 of 1050000 


MCMCpaircompare iteration 470001 of 1050000 


MCMCpaircompare iteration 480001 of 1050000 


MCMCpaircompare iteration 490001 of 1050000 


MCMCpaircompare iteration 500001 of 1050000 


MCMCpaircompare iteration 510001 of 1050000 


MCMCpaircompare iteration 520001 of 1050000 


MCMCpaircompare iteration 530001 of 1050000 


MCMCpaircompare iteration 540001 of 1050000 


MCMCpaircompare iteration 550001 of 1050000 


MCMCpaircompare iteration 560001 of 1050000 


MCMCpaircompare iteration 570001 of 1050000 


MCMCpaircompare iteration 580001 of 1050000 


MCMCpaircompare iteration 590001 of 1050000 


MCMCpaircompare iteration 600001 of 1050000 


MCMCpaircompare iteration 610001 of 1050000 


MCMCpaircompare iteration 620001 of 1050000 


MCMCpaircompare iteration 630001 of 1050000 


MCMCpaircompare iteration 640001 of 1050000 


MCMCpaircompare iteration 650001 of 1050000 


MCMCpaircompare iteration 660001 of 1050000 


MCMCpaircompare iteration 670001 of 1050000 


MCMCpaircompare iteration 680001 of 1050000 


MCMCpaircompare iteration 690001 of 1050000 


MCMCpaircompare iteration 700001 of 1050000 


MCMCpaircompare iteration 710001 of 1050000 


MCMCpaircompare iteration 720001 of 1050000 


MCMCpaircompare iteration 730001 of 1050000 


MCMCpaircompare iteration 740001 of 1050000 


MCMCpaircompare iteration 750001 of 1050000 


MCMCpaircompare iteration 760001 of 1050000 


MCMCpaircompare iteration 770001 of 1050000 


MCMCpaircompare iteration 780001 of 1050000 


MCMCpaircompare iteration 790001 of 1050000 


MCMCpaircompare iteration 800001 of 1050000 


MCMCpaircompare iteration 810001 of 1050000 


MCMCpaircompare iteration 820001 of 1050000 


MCMCpaircompare iteration 830001 of 1050000 


MCMCpaircompare iteration 840001 of 1050000 


MCMCpaircompare iteration 850001 of 1050000 


MCMCpaircompare iteration 860001 of 1050000 


MCMCpaircompare iteration 870001 of 1050000 


MCMCpaircompare iteration 880001 of 1050000 


MCMCpaircompare iteration 890001 of 1050000 


MCMCpaircompare iteration 900001 of 1050000 


MCMCpaircompare iteration 910001 of 1050000 


MCMCpaircompare iteration 920001 of 1050000 


MCMCpaircompare iteration 930001 of 1050000 


MCMCpaircompare iteration 940001 of 1050000 


MCMCpaircompare iteration 950001 of 1050000 


MCMCpaircompare iteration 960001 of 1050000 


MCMCpaircompare iteration 970001 of 1050000 


MCMCpaircompare iteration 980001 of 1050000 


MCMCpaircompare iteration 990001 of 1050000 


MCMCpaircompare iteration 1000001 of 1050000 


MCMCpaircompare iteration 1010001 of 1050000 


MCMCpaircompare iteration 1020001 of 1050000 


MCMCpaircompare iteration 1030001 of 1050000 


MCMCpaircompare iteration 1040001 of 1050000 
> 
> 
> save(b1.pairwise.out, file="MM3.2.b1.pairwise.out.Rda")
> 
> proc.time()
   user  system elapsed 
102.036   0.381 170.681 
